Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
replace words that starts with "(uuid: )"

I would like to replace text using javascript/regex

"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."

with

TV 'my-samsung' is already switched off.

by removing text (UUID: ) and replace " with '

Looks like regex can be used

  \([\s\S]*?\) 

https://regex101.com/r/xXDncn/1

or have also tried using replace method in JS

   str = str.replace("(UUID", "");
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/\s*\(UUID:[^()]*\)/g, '').replace(/^[\s"]+|[\s"]+$/g, '').replaceAll('"', "'")
)

See the first regex demo. It matches

  • \s* - zero or more whitespaces
  • \(UUID: - (UUID: string
  • [^()]* - zero or more chars other than ( and )
  • \) - a ) char.

The g flag makes it replace all occurrences.

The second regex removes trailing and leading whitespace and double quotation marks:

  • ^[\s"]+ - one or more whitespaces and double quotes at the start of string
  • | - or
  • [\s"]+$ - one or more whitespaces and double quotes at the end of string.

The .replaceAll('"', "'") is necessary to replace all " with ' chars.

It is not a good idea to merge these two operations into one as the replacements are different. Here is how it could be done, just for learning purposes:

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/^[\s"]+|[\s"]+$|\s*\(UUID:[^()]*\)|(")/g, (x,y) => y ? "'" : "")
)

That is, " is captured into Group 1, the replacement is now a callable, where x is the whole match and y is the Group 1 contents. If Group 1 matched, the replacement is ', else, the replacement is an empty string (to remove the match found).

about 4 years ago · Juan Pablo Isaza Relatório

0

you can try this

str.replace(/\(.*?\)/, "")
str.replace(/\(.*?\)/, "with")

--- update ---

const str = `"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."`;
const a = str.replace(/"(.*?)\(.*\)(.*)"/, (a, b, c) => {
    return b.replace(/"/g, "'") + c
});
console.log(a); //TV 'my-samsung' is already switched off. 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda